package com.komorebi.friends.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.komorebi.friends.model.dto.groupMsg.GroupMsgQueryRequest;
import com.komorebi.friends.model.dto.groupMsg.GroupMsgRequest;
import com.komorebi.friends.model.entity.GroupMsgContent;
import com.komorebi.friends.model.entity.User;
import com.komorebi.friends.service.GroupMsgContentService;
import com.komorebi.friends.mapper.GroupMsgContentMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author LX-MF
* @description 针对表【group_msg_content(群聊消息列表)】的数据库操作Service实现
* @createDate 2024-11-23 16:22:34
*/
@Service
public class GroupMsgContentServiceImpl extends ServiceImpl<GroupMsgContentMapper, GroupMsgContent>
    implements GroupMsgContentService{


    @Override
    public void insert(User loginUser, GroupMsgRequest groupMsgRequest) {
        GroupMsgContent groupMsgContent = groupMsgRequest.getGroupMsgContent();
        groupMsgContent.setUserId(loginUser.getId());
        groupMsgContent.setUserName(loginUser.getUserName());
        groupMsgContent.setUserProfile(loginUser.getUserProfile());
        groupMsgContent.setTeamId(groupMsgContent.getTeamId());
        this.save(groupMsgContent);
    }

    @Override
    public QueryWrapper<GroupMsgContent> getQueryMapper(GroupMsgQueryRequest groupMsgQueryRequest) {
        Long id = groupMsgQueryRequest.getId();
        Long teamId = groupMsgQueryRequest.getTeamId();
        Long userId = groupMsgQueryRequest.getUserId();
        String userName = groupMsgQueryRequest.getUserName();
        String content = groupMsgQueryRequest.getContent();
        Integer messageType = groupMsgQueryRequest.getMessageType();
        Date createTime = groupMsgQueryRequest.getCreateTime();
        //构造 queryWrapper
        QueryWrapper<GroupMsgContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(id != null, "id", id);
        queryWrapper.eq(teamId != null, "teamId", teamId);
        queryWrapper.eq(userId != null, "userId", userId);
        queryWrapper.like(StringUtils.isNotBlank(userName), "userName", userName);
        queryWrapper.like(StringUtils.isNotBlank(content), "content", content);
        queryWrapper.eq(messageType != null, "messageType", messageType);
        queryWrapper.eq(createTime != null, "createTime", createTime);

        return queryWrapper;
    }
}




